<template>
	<view >
		<view style="background: #eee; "  >
			<u-row customStyle="padding:15rpx 10rpx;border-radius: 15rpx;">
				<u-col span="1.5" offset=".5">
					<u--text text="会员:"></u--text>
				</u-col>
				<u-col span="2.5">
					<u--text v-if="userInfo.level == -2" text=" 试用版 " color="#3c9cff" bold=""></u--text>
					<u--text v-else-if="userInfo.level >-1 && userInfo.level   <3 " text="正式会员" color="#3c9cff" bold="">
					</u--text>
					<u--text v-else text=" " color="#3c9cff" bold=""></u--text>
				</u-col>
				<u-col span="2.5">
					<u--text text="截止日期:" siz></u--text>
				</u-col>
				<u-col span="3.3">
					<u--text v-if="userInfo.vip_end_time" mode="date" :text="userInfo.vip_end_time"></u--text>
					<u--text v-else  text="无"></u--text>
				</u-col>
				<u-col span="2" v-if="userInfo.level < 2 && userInfo.level != 2">
					<u-button type="success" :plain="true" text="去升级" size="mini" @click="vip"></u-button>
				</u-col>
			</u-row>
		</view>
		<view style="padding: 0 32rpx; ">
		
			<u-radio-group v-model="nowStorId" placement="column" @change="nowShopChange">
				<view class="" v-if="item.shop_name" v-for="(item,index) in shopList" :key="index">
			
					<u-row class="u-m-t-20" customStyle="margin: 15rpx 0;">
						<u-col span=".5">
			
						</u-col>
						<u-col span="3">
							<u--text :text='item.shop_name'></u--text>
						</u-col>
						<u-col span="7">
							<view style="display: flex;justify-content: space-around ;">
								<u-tag text="我的" v-if="item.owner_id == userInfo.id" type="error" size="mini"></u-tag>
								<u-tag text="基础" v-if="item.id == userInfo.store_id" type="error" size="mini">
			
								</u-tag>
								<u-tag text="店员管理 " v-if="item.owner_id == userInfo.id" @click="stafList(item.id)"
									type="primary" plain size="mini"></u-tag>
								<u-tag text="编辑" v-if="item.owner_id == userInfo.id" @click="toEdit(item.id,item.shop_name)"
									size="mini"></u-tag>
								<u-tag text="已加入" v-else type="success" size="mini"></u-tag>
			
							</view>
						</u-col>
			
						<u-col span="1.5">
							<u-radio :customStyle="{ }" size="18" :name="item.id" shape='square'>
							</u-radio>
						</u-col>
					</u-row>
					<u-line class="u-m-t-20 "></u-line>
			
				</view>
			
			</u-radio-group>
			
			
			<view class="btn" style="margin-bottom: 20rpx;">
				<u-button type="primary" text="添加店铺" @click="add"> </u-button>
			</view>
			<u-modal :show="modalShow" title='提示' cancelText='返回' @cancel='cancel' :showCancelButton='true'
				confirmText='去解锁' :content='mContent' @close='cancel' @confirm="confirm" ref="uModal" :asyncClose="true">
			</u-modal>
		</view>
		
	</view>
</template>

<script>
	var that

	var UserInfo = require('../../../service/UserInfo.js'),
		mUserInfo
	var ERShoopManage = require('../../../service/ERShoopManage.js'),
		mERShoopManage
	export default {

		data() {
			return {
				nowStorId: '',
				autoStatus: false,
				myShop: {},
				baseShop: {},
				shopList: [],
				interests: 0,
				jurisdiction: [{
					type: '一店一人',
					addStaf: false,
					addShop: false,
				}, {
					type: '一店多人',
					addStaf: true,
					addShop: false,
				}, {
					type: '多店多人',
					addStaf: true,
					addShop: true,
				}],
				svalue: 'userS',
				mContent: '添加门店权限仅连锁版本等级用户，连锁版本可以多店管理；如需升级为连锁版本等级用户，请点击去升级按钮；',
				modalShow: false,
				userInfo: {}
			}
		},
		onLoad() {
			that = this
			mUserInfo = new UserInfo(this.mNetTool)
			mERShoopManage = new ERShoopManage(this.mNetTool)
		},
		mounted() {
			let userInfo = uni.getStorageSync('userInfo')
			that.userInfo = userInfo
			// // 从缓存中获取店铺列表
			// let shopList = uni.getStorageSync('shopList')
			// if(shopList){
			// 	that.shopList = shopList
			// 	this.getShop()
			// }else{
			// 	this.getShop()
			// }


			mUserInfo = new UserInfo(this.mNetTool)
		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				uni.showModal({
					content: '请登录后使用',
					success(r) {
						if (r.confirm) {
							if (that.autoStatus) { //支持一键登录
								console.log(that.autoStatus)
								that.keyLogin()
							} else {
								uni.navigateTo({
									url: '../login/login'
								})
							}
						} else {
							uni.navigateBack({

							})
						}
					}
				})
			}
			that.userInfo = userInfo
			let shopList = uni.getStorageSync('shopList')
			if (shopList) {
				that.shopList = shopList
			}
			if (userInfo.store_ids && userInfo.level > 1) {
				// mERShoopManage.list({owner_id:userInfo.id},res =>{
				// 	console.log(res)
				// 	that.otherShop = res.rows
				// })
			}
			this.getShop();
			let viewShopListItem = uni.getStorageSync('viewShopListItem')
			if (viewShopListItem) {
				that.nowStorId = viewShopListItem.id
			}
		},
		methods: {
			nowShopChange(e) {
				console.log(e)
				that.shopList.forEach(item => {
					if (item.id == e) {
						uni.setStorageSync('viewShopListItem', item)
						uni.removeStorageSync('shelfList')
						uni.$u.toast("您以切换到 ：" + item.shop_name + " ")
					}
				})
			},
			getShop() {
				let userInfo = uni.getStorageSync('userInfo')
				if (userInfo) {
					mERShoopManage.list({
						own_user_id: userInfo.id,
						rows: 100
					}, R => {
						this.shopList = R.rows;
					})
				}

			},
			initUserInfo(m, fn) { //获取到手机号

				if (m) {
					console.log(m)
					let date = {
						mobile: m
					}
					mUserInfo.login(m, res => {
						typeof fn == "function" && fn(res);
					})
				}
				console.log(123213)
			},
			vip() {
				uni.navigateTo({
					url: '../VIP/VIP'
				})
			},
			toEditBase(id) {
				uni.navigateTo({
					url: 'editShop/editShop?base=true&shopId=' + id
				})
			},
			toEdit(id, name) {
				console.log(id)
				uni.navigateTo({
					url: 'editShop/editShop?shopId=' + id + '&name=' + name
				})
			},
			stafListBase(id) {
				uni.navigateTo({
					url: '../staffList/staffList?base=true&shopId=' + id
				})
			},
			stafList(id) {

				console.log(id)
				uni.navigateTo({
					url: '../staffList/staffList?shopId=' + id
				})
			},
			isSelect() {
				uni.$u.toast('切换成功')

			},
			confirm() {
				that.modalShow = false
				uni.navigateTo({
					url: '../VIP/VIP'
				})
			},
			cancel() {
				this.modalShow = false
			},
			add() {
				mUserInfo.isVip(res => {
					console.log(res)
					if(res.success){
						
					}else{
						uni.$u.toast('您的会员已过期，请充值')
						return
					}
				})
				if(that.shopList.length >=10 && that.userInfo.level <= 1){
					uni.$u.toast('您 店铺已达上限')
				}
				let shopList = uni.getStorageSync('shopList')
				console.log(shopList.length == 0)
				if (shopList.length == 0) {
					uni.navigateTo({
						url: 'addShop/addShop'
					})
					return
				}
				if (that.userInfo.level <= 1) {
					// uni.$u.toast('抱歉，您的会员等级不够，请升级会员')
					this.modalShow = true
					return
				} else {
					uni.navigateTo({
						url: 'addShop/addShop'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		width: 700rpx;
		position: fixed;
		bottom: 15rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>
